/**
 * @(#) EpuckSoundActuator.java
 */

package pcsr.drivers.epuckDriver;

import pcsr.drivers.epuckDriver.command.IePuckUartProtocol.Sounds;

class EpuckSoundActuator implements IEpuckActuator
{
	private EPuck epuckrobot;
	private Sounds sound;
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public String GetID() {
		return EpuckActuatorType.SOUND.name();
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public EpuckActuatorMode GetMode() {
		return EpuckActuatorMode.SETVALUEONLY;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public EpuckActuatorType GetType() {
		return EpuckActuatorType.SOUND;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public short GetValue() {
		return (short)(sound != null ? sound.ID() : -1) ;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void SetValue(short newValue) {
		SetSound(newValue);
		
		if(sound != null)
		{
			epuckrobot.SendActuatorUpdateCommand(this);
		}
	}
	
	/**
	 * @param newValue
	 */
	private void SetSound(short newValue) {
		switch (newValue) {
		case 1:		
			sound = Sounds.SOUND_1;
			break;
		case 2:
			sound = Sounds.SOUND_2;
			break;
		case 3:
			sound = Sounds.SOUND_3;
			break;
		case 4:
			sound = Sounds.SOUND_4;
			break;
		case 5:
			sound = Sounds.SOUND_5;
			break;
		default:
			break;
		}
	}

	Sounds GetSound()
	{
		return sound;
	}

	public EpuckSoundActuator(EPuck owner) {
		epuckrobot = owner;
	}
	
}
